package com.PAT.UnSatisfying;

import java.util.HashMap;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/19/14:39
 * @Description:
 * @Target: 输入一堆数据,算出最大和值,打印,使用HashMap
 */
public class 挖掘机技术哪家强 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        HashMap<Integer, Integer> map = new HashMap<>();
        int maxNum = Integer.MIN_VALUE;
        int maxGrade = Integer.MIN_VALUE;
        while (n-->0){
            int num = scanner.nextInt();
            int grade = scanner.nextInt();
            int tempGrade = saveNumAndGrade(map,num,grade);
            if(tempGrade!=grade){
                map.put(num,tempGrade);
                if (tempGrade>maxGrade){
                    maxNum = num;
                    maxGrade = tempGrade;
                }
            }else {
                map.put(num,grade);
                if (grade>maxGrade){
                    maxNum = num;
                    maxGrade = grade;
                }
            }
        }


        System.out.println(maxNum+" "+maxGrade);

    }



    // 判定方法,i和成绩,如果i在,成绩加,i不在,i进去,成绩加,
    // 送入HashMap,sum,grade返回成绩...
    public static int saveNumAndGrade(HashMap<Integer, Integer> map ,int num,int grade){
        int sum = 0;
        if (map.containsKey(num)){
            sum = map.get(num)+grade;
        }else {
            sum = grade;
        }

        return sum;
    }
}
